package com.gc.cscott.providers;

import com.gc.cscott.domain.Platform;
import com.gc.cscott.domain.PlatformsList;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Provider;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;
import org.apache.commons.io.FileUtils;

/**
 *
 *
 *
 *
 *
 * @author root
 */
public class PlatformsListProvider implements Provider<PlatformsList> {
    public PlatformsList get() {
        try {
            Gson gson = new Gson();
            String json = FileUtils.readFileToString(new File("platforms.json"), "UTF-8");

            Type typeOfT = new TypeToken<List<Platform>>() {}.getType();
            List<Platform> platforms = gson.fromJson(json, typeOfT);
            return new PlatformsList(platforms);
        } catch (IOException ex) {
            throw new Error("Failed to load platforms configuration",ex);
        }
    }
}
